#ifndef tool_ui_h
#define tool_ui_h

#import "tool.h"

/*rect describe by center and size
*/
typedef struct UICenterRect_
{
	CGPoint center;
	CGSize size;
}
UICenterRect;

/*image describe by file path and position
*/
typedef struct UIImageObject_
{
	char path[STRING_BUF_SIZE];
	CGPoint position;
}
UIImageObject;

/*animation describe by file path and delay
*/
typedef struct UIAnimationObject_
{
	std::vector<std::string> path_table;
	float delay;
	float total_time;
}
UIAnimationObject;

/*image menu item describe by normal, selectec, disabled file path and position
*/
typedef struct UIMenuItemImageObject_
{
	char path_normal[STRING_BUF_SIZE];
	char path_selected[STRING_BUF_SIZE];
	char path_disabled[STRING_BUF_SIZE];
	CGPoint position;
}
UIMenuItemImageObject;

/*animation menu item
*/
typedef struct UIMenuItemAniObject_
{
	char path[STRING_BUF_SIZE];
	UIAnimationObject ani;
	CGPoint position;
}
UIMenuItemAniObject;

/*object clear
*/
void uiClearAnimationObject(UIAnimationObject *Obj);

/*load data resource form XML file
*/
void uiLoadColorFromXML(mxml_node_t *Element, ccColor3B *Buf);
void uiLoadPointFromXML(mxml_node_t *Element, CGPoint *Buf);
void uiLoadSizeFromXML(mxml_node_t *Element, CGSize *Buf);
void uiLoadCenterRectFromXML(mxml_node_t *Element, UICenterRect *Buf);
void uiLoadImageObjectFromXML(mxml_node_t *Element, UIImageObject *Object);
void uiLoadAnimationObjectFromXML(mxml_node_t *Element, UIAnimationObject *Object);
void uiLoadMenuItemImageObjectFromXML(mxml_node_t *Element, UIMenuItemImageObject *Object);
void uiLoadMenuItemAniObjectFromXML(mxml_node_t *Element, UIMenuItemAniObject *Object);

/*create object by data resource
*/
CCSprite *uiCreateImageObject(UIImageObject const *Object, CCNode *Node);
CCAnimation *uiCreateAnimationObject(UIAnimationObject const *Object);
CCAnimation *uiCreateAnimationReverseObject(UIAnimationObject const *Object);
CCMenuItemImage *uiCreateMenuItemImageObject(UIMenuItemImageObject const *Object, CCNode *Node, SEL Sel);
CCMenuItemImage *uiCreateMenuItemAniObject(UIMenuItemAniObject const *Object, CCNode *Node, SEL Sel);

/*add object to cocos2d node
*/
CCMenu *uiNodeAddMenu(id Node, CGPoint Position, CCMenuItem *Item, ...);   /*...,end by nil*/
CCSprite *uiNodeAddImage(id Node, NSString *Path, int Z, CGPoint Position);

/*check if a point in a center rect
*/
bool uiPointInCenterRect(CGPoint Point, UICenterRect Rect);

/*render use gl
*/
void uiRenderLine(CGPoint Point1, CGPoint Point2);
void uiRenderTriangle(CGPoint Point1, CGPoint Point2, CGPoint Point3);
void uiRenderRect(UICenterRect Rect);

#endif